package se.kth.fericss.rts;

import org.newdawn.slick.Color;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.geom.Rectangle;

import se.kth.fericss.obj.GameObject;

public class Minimap {
	private Game game;
	private World world;
	private View worldView;
	private final int minimapWidth = 250; //TODO take out minimap out of the names?
	private final int minimapHeight = 250;
	private final int minimapX;
	private final int minimapY;
	private final float scaleX;
	private final float scaleY;

	public Minimap(Game game, World world, View worldView) {
		this.game = game;
		this.world = world;
		this.worldView = worldView;
		minimapX = 0;
		minimapY = worldView.getScreenSize().height - minimapHeight;
		scaleX = world.getWidth() / (float)minimapWidth;
		scaleY = world.getHeight() / (float)minimapHeight;
	}

	public int getMinimapX() {
		return minimapX;
	}

	public int getMinimapY() {
		return minimapY;
	}

	public float getScaleX() {
		return scaleX;
	}

	public float getScaleY() {
		return scaleY;
	}

	public int getMinimapHeight() {
		return minimapHeight;
	}

	public int getMinimapWidth() {
		return minimapWidth;
	}

	public Rectangle getMinimapBoundary() {
		return new Rectangle(minimapX, minimapY, minimapWidth, minimapHeight);
	}

	/**
	 * Draws the minimap in the top right corner of the screen.
	 * The minimap includes a rectangle showing what part of the map is viewed at the moment.
	 * Also draws all units and buildings in their team's color.
	 */
	public void draw(Graphics g) {
		//Draw background
		g.setColor(new Color(40, 40, 40));
		g.fillRect(minimapX, minimapY, minimapWidth, minimapHeight);

		//Draw resources such as trees
		//for(GameObject object : world.getAllUnits()) {
		//	if(object instanceof Tree) {
		//		g.setColor(Color.green);
		//		g.fillRect(minimapX + object.getX() / scaleX, minimapY + object.getY() / scaleY, 3, 3);
		//	}
		//}

		//Draw all units and buildings in their team's color
		//for(ControllableObject object : world.getControllableObjects()) {
		//	if(object.isSelected()) {
		//		g.setColor(Color.white);
		//	} else {
		//		g.setColor(object.getTeam().getTeamColor());
		//	}

		//	g.fillRect(minimapX + object.getX() / scaleX, minimapY + object.getY() / scaleY, 3, 3);
		//}

		//Draw the view rectangle
		g.setColor(Color.white);
		Rectangle viewRect = worldView.getViewLocationRect();
		g.drawRect(minimapX - viewRect.getX() / scaleX, minimapY - viewRect.getY() / scaleY, (int)(viewRect.getWidth() / scaleX), (int)(viewRect.getHeight() / scaleY));
	}
}
